﻿Public Class Logon
#Region "Timers and Clock"
    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Label2.Text = TimeOfDay()
    End Sub

    Private Sub Logon_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Timer1.Enabled = True
        Timer1.Start()
    End Sub
#End Region
#Region "Clear When Click"
    Private Sub TextBox1_Click(sender As Object, e As EventArgs) Handles TextBox1.Click
        TextBox1.Clear()
    End Sub

    Private Sub TextBox2_Click(sender As Object, e As EventArgs) Handles TextBox2.Click
        TextBox2.Clear()
    End Sub
#End Region
#Region "Login Script"
    Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
        If TextBox1.Text = "" Then
            MsgBox(MsgBoxStyle.OkOnly, "Error, More than one character required")
        Else
            If My.Computer.FileSystem.DirectoryExists("%appdata%\AliveOS\Open\" + TextBox1.Text + "\") Then
                Dim USERREAD As System.IO.StreamReader = New System.IO.StreamReader("%appdata%\AliveOS\Open\" + TextBox1.Text + "\" + "USERNAME.TXT")
                Dim userline As String
                Dim PASSREAD As System.IO.StreamReader = New System.IO.StreamReader("%appdata%\AliveOS\Open\" + TextBox1.Text + "\" + "PASSWORD.TXT")
                Dim passline As String
                Do
                    passline = TextBox2.Text
                    userline = USERREAD.ReadLine
                    Console.WriteLine(passline)
                    Console.WriteLine(userline)
                Loop Until userline Is Nothing
                If TextBox2.Text = "" Then
                    MsgBox(MsgBoxStyle.OkOnly, "Error, please insert a password")
                Else
                    If passline = PASSREAD.ReadLine() = True Then
                        Label1.Text = "You're Logged In"
                        Desktop.Show()
                    End If
                End If
            Else
                MsgBox(MsgBoxStyle.OkOnly, "The Username is Invalid")
            End If
        End If
    End Sub
#End Region
End Class